<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>酒店房间分类管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">

</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">房间分类管理</div>
                <div class="layui-card-body">

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn">
                                <button class="layui-btn" data-type="addadmin">添加房间类型</button>
                            </div>
                        </div>
                    </div>

                    <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate">

                        <script type="text/html" id="is_display_switch">
                            <input type="checkbox" name="is_display" lay-skin="switch" lay-text="上架|下架" lay-filter="is_display_switch"
                                   value="{{ d.is_display }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.is_display == 0 ? 'checked' : '' }}>
                        </script>

                    </table>

                    <script type="text/html" id="test-table-operate-barDemo">
                        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="showDetial">房间详情</a>
                        <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="showImg">房间图片</a>
                        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<!--添加弹窗-->
<div id="addmodal" style="display: none;padding:20px;">
    <form class="layui-form" action="" lay-filter="component-form-group">

        <div class="layui-form-item">
            <label class="layui-form-label">*房间类型</label>
            <div class="layui-input-block">
                <input type="text" name="room_name" lay-verify="required" placeholder="请输入分类名称，例如：商务大床房" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">*房间价格</label>
                <div class="layui-input-block">
                    <input type="text" name="room_price" lay-verify="required|number" id="addpassword" placeholder="请输入房间价格" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">*是否优惠</label>
                <div class="layui-input-block">
                    <input type="checkbox"  name="is_tehui" value="1" lay-skin="switch" lay-text="是|否">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">优惠价格</label>
                <div class="layui-input-block">
                    <input type="text" name="room_discount_price" placeholder="请输入优惠价格" autocomplete="off" class="layui-input">
                </div>
            </div> 
        </div>
      <div class="layui-form-item">  
         <div class="layui-inline">
                <label class="layui-form-label">*是否可取消</label>
                <div class="layui-input-block">
                    <input type="checkbox"  name="is_quxiao" value="1" lay-skin="switch" lay-text="是|否">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">可取消时间</label>
                <div class="layui-input-block">
                    <input type="text" name="cancelable_time" placeholder="HH:mm:ss"  id="test4" autocomplete="off" class="layui-input">
                </div>
            </div>  
             <div class="layui-inline">
                <label class="layui-form-label">库存</label>
                <div class="layui-input-block">
                    <input type="text" name="room_count" placeholder="请输入当前库存" autocomplete="off" class="layui-input">
                </div>
            </div> 
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">*房间面积</label>
                <div class="layui-input-block">
                    <input type="text" name="square" placeholder="单位：平方米" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">*可入住人数</label>
                <div class="layui-input-block">
                    <input type="text" name="available_person" lay-verify="required|number" placeholder="可入住人数" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">*床铺描述</label>
                <div class="layui-input-block">
                    <input type="text" name="bed_scale" placeholder="例如：1.8米双人大床" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div> 
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">*客服设施</label>
            <div class="layui-input-block">
                 
                  {foreach $room_kinds['room'] as $k=>$v} 
                     <div class="layui-inline">
                        <label class="layui-form-label">*{$v['data_name']}</label>
                        <div class="layui-input-block">
                          <input type="checkbox"  name="1-{$v['id']}" id="" value="{$v['id']}" lay-skin="switch" lay-text="有|无">
                        </div>
                      </div>
                  {/foreach} 
               
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">配套服务</label>
            <div class="layui-input-block"> 
           {foreach $room_kinds['assort'] as $k=>$v} 
                     <div class="layui-inline">
                        <label class="layui-form-label">*{$v['data_name']}</label>
                        <div class="layui-input-block">
                          <input type="checkbox"  name="2-{$v['id']}" id="" value="{$v['id']}" lay-skin="switch" lay-text="有|无">
                        </div>
                      </div>
                  {/foreach} 
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">餐饮</label>
           <div class="layui-input-block"> 
               {foreach $room_kinds['catering'] as $k=>$v} 
                     <div class="layui-inline">
                        <label class="layui-form-label">*{$v['data_name']}</label>
                        <div class="layui-input-block">
                          <input type="checkbox"  name="3-{$v['id']}" id="" value="{$v['id']}" lay-skin="switch" lay-text="有|无">
                        </div>
                      </div>
                  {/foreach} 
            </div>
        </div>

        <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
                <div class="layui-inline" style="left: 0;">
                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="addsubmit">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </form>
</div>

<!--修改弹窗-->
<div id="editmodal" style="display: none;padding:20px;">
    <form class="layui-form" action="" lay-filter="component-form-group">

        <input type="hidden" id="edit_room_id" name="room_id">
        
        <div class="layui-form-item">
            <label class="layui-form-label">*房名类型</label>
            <div class="layui-input-block">
                <input type="text" name="room_name" id="edit_room_name" lay-verify="required" placeholder="请输入分类名称，例如：商务大床房" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">*房间价格</label>
                <div class="layui-input-block">
                    <input type="text" name="room_price" id="edit_room_price" lay-verify="required|number" id="addpassword" placeholder="请输入房间价格" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">*是否优惠</label>
                <div class="layui-input-block">
                    <input type="radio" name="is_tehui" id="edit_is_tehui1" value="1" title="是">
                    <input type="radio" name="is_tehui" id="edit_is_tehui2" value="0" title="否">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">优惠价格</label>
                <div class="layui-input-block">
                    <input type="text" name="room_discount_price" id="edit_room_discount_price" placeholder="请输入优惠价格" autocomplete="off" class="layui-input">
                </div>
            </div>

           
        </div>
         <div class="layui-form-item">  
         <div class="layui-inline">
                <label class="layui-form-label">*是否可取消</label>
                <div class="layui-input-block">
                    <input type="checkbox"  name="is_quxiao" id="edit_is_quxiao" value="1" lay-skin="switch" lay-text="是|否">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">可取消时间</label>
                <div class="layui-input-block">
                    <input type="text" name="cancelable_time" id="edit_cancelable_time" placeholder="HH:mm:ss"  autocomplete="off" class="layui-input">
                </div>
            </div>
             <div class="layui-inline">
                <label class="layui-form-label">库存</label>
                <div class="layui-input-block">
                    <input type="text" name="room_count" id="edit_room_count" placeholder="请输入当前库存" autocomplete="off" class="layui-input">
                </div>
            </div>   
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">*房间面积</label>
                <div class="layui-input-block">
                    <input type="text" name="square" id="edit_square" placeholder="单位：平方米" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">*可入住人数</label>
                <div class="layui-input-block">
                    <input type="text" name="available_person" id="edit_available_person" lay-verify="required|number" placeholder="可入住人数" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">*床铺描述</label>
                <div class="layui-input-block">
                    <input type="text" name="bed_scale" id="edit_bed_scale" placeholder="例如：1.8米双人大床" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
  
         <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">*客服设施</label>
            <div class="layui-input-block">
                 
                  {foreach $room_kinds['room'] as $k=>$v} 
                     <div class="layui-inline">
                        <label class="layui-form-label">*{$v['data_name']}</label>
                        <div class="layui-input-block">
                          <input type="checkbox"  name="1-{$v['id']}" id="room-{$v['id']}" value="{$v['id']}" lay-skin="switch" lay-text="有|无">
                        </div>
                      </div>
                  {/foreach} 
               
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">配套服务</label>
            <div class="layui-input-block"> 
           {foreach $room_kinds['assort'] as $k=>$v} 
                     <div class="layui-inline">
                        <label class="layui-form-label">*{$v['data_name']}</label>
                        <div class="layui-input-block">
                          <input type="checkbox"  name="2-{$v['id']}" id="assort-{$v['id']}" value="{$v['id']}" lay-skin="switch" lay-text="有|无">
                        </div>
                      </div>
                  {/foreach} 
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">餐饮</label>
           <div class="layui-input-block"> 
               {foreach $room_kinds['catering'] as $k=>$v} 
                     <div class="layui-inline">
                        <label class="layui-form-label">*{$v['data_name']}</label>
                        <div class="layui-input-block">
                          <input type="checkbox"  name="3-{$v['id']}" id="food-{$v['id']}" value="{$v['id']}" lay-skin="switch" lay-text="有|无">
                        </div>
                      </div>
                  {/foreach} 
            </div>
        </div>

      
       

        <div class="layui-form-item layui-layout-admin">
            <div class="layui-input-block">
                <div class="layui-inline" style="left: 0;">
                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="editsubmit">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>

    </form>
</div>

<style>
    .d_left{
        width: 150px;
        text-align: right;
        position: relative;
        float: left;
    }

    .d_right{
        width: 300px;
        position: relative;
        float: left;
        padding-left: 20px;
    }

    #detialmodal li{
        margin-bottom: 15px;
    }
</style>
<div id="detialmodal" style="display: none;padding:20px;">
    <ul>
        <li>
            <div class="d_left">房间类型：</div>
            <div class="d_right" id="room_name"></div>
            <div style="clear: both"></div>
        </li> 
        <li>
            <div class="d_left">是否特惠：</div>
            <div class="d_right" id="is_tehui">是</div>
            <div style="clear: both"></div>
        </li> 
         <li>
            <div class="d_left">房间价格：</div>
            <div class="d_right" id="room_price"></div>
            <div style="clear: both"></div>
        </li> 
         <li>
            <div class="d_left">房间优惠价格：</div>
            <div class="d_right" id="room_discount_price"></div>
            <div style="clear: both"></div>
        </li> 
        <li>
            <div class="d_left">是否可取消：</div>
            <div class="d_right" id="is_quxiao">是</div>
            <div style="clear: both"></div>
        </li> 
 
        <li>
            <div class="d_left">客房设施：</div>
            <div class="d_right" id="room_fw_other"></div>
            <div style="clear: both"></div>
        </li>

        <li>
            <div class="d_left">配套服务：</div>
            <div class="d_right" id="room_other"> </div>
            <div style="clear: both"></div>
        </li>

        <li>
            <div class="d_left">餐饮其它：</div>
            <div class="d_right" id="food_other"> </div>
            <div style="clear: both"></div>
        </li>
         <li>
            <div class="d_left">可取消时间段：</div>
            <div class="d_right" id="cancelable_time"> </div>
            <div style="clear: both"></div>
        </li>
    </ul>
</div>

<script src="/static/layuiadmin/layui/layui.js"></script>
<script>  
 layui.use('laydate', function(){
     var laydate = layui.laydate;
      laydate.render({
        elem: '#test4'
        ,type: 'time' 
      }); 
    }); 
 
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate','set'], function(){
        $ = layui.jquery;
        var table = layui.table
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form;

        table.render({
            elem: '#test-table-operate'
            ,url: "{:url('Room/roomKinds')}"
            ,height: 'full-155'
            ,cols: [[
                 {field:'room_name',align:'center',width:200,  title: '房间名称'}
                ,{field:'room_price',align:'center',   title: '房间价格'}
                ,{field:'is_tehui',align:'center',   title: '是否特惠',templet:function(d){
                    if (d.is_tehui == 1){
                        return '是';
                    }else{
                        return '否';
                    }
                }}
                ,{field:'room_discount_price',align:'center',   title: '特惠价格'}
                ,{field:'room_count',align:'center',   title: '库存'}
                ,{field:'is_quxiao',align:'center',   title: '是否可取消',templet:function(d){
                        if (d.is_quxiao == 1){
                            return '是';
                        }else{
                            return '否';
                        }
                    }}

                ,{field:'square',align:'center',width:140,title: '房间面积（m<sup>2</sup>）'}
                ,{field:'available_person',align:'center', width:110,  title: '可入住人数'}
                ,{field:'bed_scale',align:'center',   title: '床位描述'}

                ,{field:'is_display',width:150, align:'center', title: '是否上架',templet: '#is_display_switch'}

                ,{align:'center',width:270, title: '操作',fixed: 'right', toolbar: '#test-table-operate-barDemo'}
            ]]
        });

        form.render(null, 'component-form-group');

        laydate.render({
            elem: '#LAY-component-form-group-date'
        });


        //监听工具条
        table.on('tool(test-table-operate)', function(obj){
            var data = obj.data;
          if(obj.event === 'del'){
                layer.confirm('确认删除房间类型"' + data.room_name + '"吗', function(index){
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    if (data.pid == 0) {
                        layer.msg('主账号禁止删除',{icon:2,time:1000},function(){
                            layer.closeAll();
                        });

                    }else{
                        $.ajax({
                            url: "{:url('Room/delRoom')}",
                            type: 'post',
                            dataType: 'json',
                            data: {room_id:data.room_id},
                            success: function(msg){
                                layer.close(loading);
                                if (msg.code === 0) {
                                    obj.del();
                                    layer.close(index);
                                }else if (msg.code === 1){
                                    layer.msg('删除失败',{icon:2,time:1000});
                                }
                            }
                        })
                    }
                });
            } else if(obj.event === 'edit'){                           //修改操作],

                $('#edit_room_id').val(data.room_id);
                $('#edit_room_name').val(data.room_name);
                $('#edit_room_price').val(data.room_price);
                $('#edit_room_discount_price').val(data.room_discount_price);
                $('#edit_square').val(data.square);
                $('#edit_available_person').val(data.available_person);
                $('#edit_bed_scale').val(data.bed_scale);
                $('#edit_room_subject').val(data.room_subject);
                $('#edit_room_other').val(data.room_other);
                $('#room_subject').val(data.room_subject);
                $('#edit_room_fw_other').val(data.room_fw_other);
                $('#edit_cancelable_time').val(data.cancelable_time); 
                $('#edit_room_count').val(data.room_count); 
                
                  if (data.is_quxiao == 1){
                      $('#edit_is_quxiao').prop('checked',true);
                  }else {
                      $('#edit_is_quxiao').prop('checked',false);
                  }

                  if (data.is_tehui == 1){
                      $('#edit_is_tehui1').prop('checked',true);
                  }else {
                      $('#edit_is_tehui2').prop('checked',true);
                  }
                  var room_fw_other = data.room_fw_other;
                  var room_other = data.room_other;
                  var food_other = data.food_other;
                  if(room_fw_other){ 
                     var fwarray = room_fw_other.split(",");//逗号是分隔符 
                     for(var i=0;i<fwarray.length;i++){ 
                         $('#room-'+fwarray[i]+'').prop('checked',true);
                     } 
                  }
                  if(room_other){ 
                     var roomarray = room_other.split(",");//逗号是分隔符 
                     for(var i=0;i<roomarray.length;i++){ 
                         $('#assort-'+roomarray[i]+'').prop('checked',true);
                     } 
                  }
                  if(food_other){ 
                     var foodarray = food_other.split(",");//逗号是分隔符 
                     for(var i=0;i<foodarray.length;i++){ 
                         $('#food-'+foodarray[i]+'').prop('checked',true);
                     } 
                  } 

                form.render();


                layer.open({
                    title:'修改房间分类信息'
                    ,type: 1
                    ,shadeClose: true
                    ,area: ['1200px']
                    ,content: $('#editmodal')
                });

            }else if(obj.event === 'showDetial'){ 
                var loading = layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
                var room_id = data.room_id; 
                $.ajax({
                    url: "{:url('Hotel/getRoomDetail')}",
                    type: 'post',
                    dataType: 'json',
                    data: {room_id:room_id},
                    success: function(data){
                        layer.close(loading);
                        if (data.code === 0) { 
                            var obj = data.data;   
                             $('#room_other').html(obj.room_other);
                             $('#food_other').html(obj.food_other);
                             $('#room_fw_other').html(obj.room_fw_other);
                             $('#cancelable_time').html(obj.cancelable_time);
                             $('#room_name').html(obj.room_name);
                             $('#bed_scale').html(obj.bed_scale);
                             $('#square').html(obj.square);
                             $('#available_person').html(obj.available_person);
                             $('#room_name').html(obj.room_name); 
                             $('#room_subject').html(obj.room_subject); 
                             $('#room_price').html(obj.room_price); 
                             $('#room_discount_price').html(obj.room_discount_price); 
                             if(obj.is_tehui == 0){
                                $('#is_tehui').html('否'); 
                                $('#room_discount_price').html('无'); 
                             }
                              if(obj.is_quxiao == 0){
                                $('#is_quxiao').html('否'); 
                             }

                            var userDetailModal = layer.open({
                                title:'房间分类详情'
                                ,type: 1
                                ,shadeClose: true
                                ,area:['800px']
                                ,content: $('#detialmodal')
                            });
                        }else{
                            layer.msg('获取信息失败',{icon:2,time:1000});
                        }  
                    }
                })

            }else if(obj.event == 'showImg')
            {  
                 var room_id = data.room_id; 
                $.ajax({
                    url: "{:url('Hotel/viewImage')}",
                    type: 'post',
                    dataType: 'json',
                    data: {room_id:data.room_id},
                    success: function(msg){
                        if (msg.code == 0) {
                            var arr  = msg.data;
                            let img_src_arr = [];
                            for (var i in arr) {
                                img_src_arr.push(arr[i].img_path)
                            }
                            console.log(img_src_arr);
                            var img_src_data = {};
                            img_src_data.title = '景点图片';
                            img_src_data.id = data.id;
                            img_src_data.start = 0;
                            img_src_data.data =[];

                            var src = {};

                            for(var i=0;i<img_src_arr.length;i++){
                                src = {};
                                var num = i+1;
                                src.alt = '景点图片'+ num;
                                src.pid = i;
                                src.src = img_src_arr[i];
                                src.thumb = img_src_arr[i];
                                console.log(src);
                                img_src_data.data.push(src);
                            }
                            layer.photos({
                                photos: img_src_data
                                ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                            });
                        }else{
                            layer.msg(msg.message,{time:1000});
                        }
                    }
                });
            }
        });
 layui.use('laydate', function(){
     var laydate = layui.laydate;
      laydate.render({
        elem: '#edit_cancelable_time'
        ,type: 'time' 
      }); 
    });

        //添加提交
        form.on('submit(addsubmit)', function(data){
            
            if (data.field.is_tehui){

                if (!data.field.room_discount_price){
                    layer.msg('请输入特惠价格',{time:2000});
                    return false;
                }

            }else{

                data.field.is_tehui = 0;

            }
            if (data.field.is_quxiao){

                if (!data.field.cancelable_time){
                    layer.msg('请输入可取消时间',{time:2000});
                    return false;
                }

            }else{

                data.field.is_quxiao = 0;

            }

            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });

            $.ajax({
                url: "{:url('Room/addRoomKinds')}",
                type: 'post',
                dataType: 'json',
                data: {data:data.field},
                success: function(data){
                    if (data.code === 0) {
                        layer.msg('添加成功,请上传房间图片',{icon:1,time:2000},function(){
                            window.location.reload();
                        });
                    }else{
                        layer.close(loading);
                        layer.msg('添加失败',{icon:2,time:1000});
                    }
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        //修改提交
        form.on('submit(editsubmit)', function(data){
           
             if (data.field.is_tehui == 1){ 
                if (data.field.room_discount_price == 0){ 
                    layer.msg('请输入特惠价格',{time:2000});
                    return false;
                }

            }else{

                data.field.is_tehui = 0;

            }
            if (data.field.is_quxiao == 1){

                if (data.field.cancelable_time == "00:00:00"){
                    layer.msg('请输入可取消时间',{time:2000});
                    return false;
                }

            }else{

                data.field.is_quxiao = 0;

            }
             var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            $.ajax({
                url: "{:url('Room/editRoomKinds')}",
                type: 'post',
                dataType: 'json',
                data: {data:data.field},
                success: function(info){
                    if (info.code === 0) {
                        layer.msg('修改成功',{icon:1,time:2000},function(){
                            window.location.reload();
                        });
                    }else{
                        layer.close(loading);
                        layer.msg(info.code,{icon:2,time:1000})
                    }
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        //开关修改管理员状态
        form.on('switch(is_display_switch)', function(obj){
            var loading = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            json = table.clearCacheKey(json); 
            var is_display = this.checked ? '0' : '1';

            $.ajax({
                url: "{:url('Room/editRoomKindsDisplay')}",
                type: 'post',
                dataType: 'json',
                data: {room_id:json.room_id,is_display:is_display},
                success: function(info){
                    if (info.code === 0) {
                        layer.close(loading);
                    }else{
                        layer.msg(info.msg,{icon:1,time:1000},function(){
                            window.location.reload();
                        });
                    }
                }
            })
        });

        var $ = layui.$, active = {
            addadmin: function() {
                var addmodal = layer.open({
                    title: '添加房间类型'
                    , type: 1
                    , shadeClose: true
                    , area: ['1100px']
                    , content: $('#addmodal')
                });
            }

        };

        $('.test-table-operate-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });


    //格式化时间函数
    function Format(datetime,fmt) {
        if (parseInt(datetime)==datetime) {
            if (datetime.length==10) {
                datetime=parseInt(datetime)*1000;
            } else if(datetime.length==13) {
                datetime=parseInt(datetime);
            }
        }
        datetime=new Date(datetime);
        var o = {
            "M+" : datetime.getMonth()+1,                 //月份
            "d+" : datetime.getDate(),                    //日
            "h+" : datetime.getHours(),                   //小时
            "m+" : datetime.getMinutes(),                 //分
            "s+" : datetime.getSeconds(),                 //秒
            "q+" : Math.floor((datetime.getMonth()+3)/3), //季度
            "S"  : datetime.getMilliseconds()             //毫秒
        };
        if(/(y+)/.test(fmt))
            fmt=fmt.replace(RegExp.$1, (datetime.getFullYear()+"").substr(4 - RegExp.$1.length));
        for(var k in o)
            if(new RegExp("("+ k +")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        return fmt;
    }

</script>


</body>
</html>